package top.huntwolf.admin.controller;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.huntwolf.admin.annotation.URLControl;
import top.huntwolf.admin.annotation.URLMessage;
import top.huntwolf.admin.common.JsonResult;
import top.huntwolf.admin.pojo.Address;
import top.huntwolf.admin.service.AddressService;

import java.util.List;

@URLControl
@Api(description = "地址控制器")
@RestController
@CrossOrigin
@RequestMapping(value = "/address")
public class AddressController {

    @Autowired
    private AddressService addressService;

    @URLMessage(url = "/address/**")
    @PostMapping("")
    @ApiOperation("增加地址")
    public JsonResult addAddress(@RequestBody Address address){

        addressService.insert(address);
        return JsonResult.success(null);
    }

    @DeleteMapping("/{addressId}")
    @ApiOperation("删除地址")
    public JsonResult deleteAddress(@PathVariable Integer addressId){

        addressService.delete(addressId);
        return JsonResult.success(null);

    }

    @PutMapping("")
    @ApiOperation("修改")
    public JsonResult updateAddress(@RequestBody Address address){

        addressService.update(address);
        return JsonResult.success(null);

    }

    @GetMapping("")
    @ApiOperation("显示所有地址")
    public JsonResult<List<Address>> selectAddress(){
        List<Address> addresses = addressService.select();
        return JsonResult.success(addresses);
    }


}
